package com.example.studentstatusmanagement.controller;

import com.example.studentstatusmanagement.config.SystemVariable;
import com.example.studentstatusmanagement.pojo.Building;
import com.example.studentstatusmanagement.pojo.SysUser;
import com.example.studentstatusmanagement.pojo.doo.ReqStudent;
import com.example.studentstatusmanagement.pojo.dto.BuildingInfo;
import com.example.studentstatusmanagement.pojo.dto.MajorInfo;
import com.example.studentstatusmanagement.pojo.dto.Student;
import com.example.studentstatusmanagement.service.DormService;
import com.example.studentstatusmanagement.service.MajorService;
import com.example.studentstatusmanagement.service.UserService;
import com.example.studentstatusmanagement.utils.ResultResponse;
import com.example.studentstatusmanagement.utils.ResultTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/v1/admin")
public class AdminController {

    @Autowired
    private UserService userService;

    @Autowired
    private MajorService majorService;

    @Autowired
    private DormService dormService;

    @RequestMapping("/showstudentinfo")
    public Map<String, Object> showStudentInfo(ReqStudent reqStudent) {

        Map<String, Object> so = new HashMap<String, Object>();

        List<Student> ls = userService.selectStudentInfo(reqStudent);

        so.put("code", SystemVariable.URL_SUCCESS);
        so.put("msg", "");
        so.put("count", ls.size());
        so.put("data", ls);

        return so;
    }
    // 返回学院专业班级两级联动
    @RequestMapping("majormenu")
    public List<MajorInfo> majorMenu(){
        return majorService.selectMajorsAndClassroomMenu();
    }

    // 返回三级联动宿舍情况
    @RequestMapping("dormmenu")
    public List<BuildingInfo> dormMenu(){
        return dormService.selectDormInfos();
    }

    @RequestMapping("updatepwd")
    public ResultResponse updatePWD(SysUser sysUser){
        if (StringUtils.isEmpty(sysUser.getId())||StringUtils.isEmpty(sysUser.getUserPassword())){
            return ResultResponse.Build(ResultTypeEnum.fail, SystemVariable.PARAM_IS_NULL);
        }
        if (userService.updateByPrimaryKeyUserSelective(sysUser) == SystemVariable.SUCCESS) {
            return ResultResponse.Build(ResultTypeEnum.success, SystemVariable.DO_SUCCESS);
        }
        return ResultResponse.Build(ResultTypeEnum.fail, SystemVariable.DO_ERROR);
    }

}
